package com.freejava.test_swagger.api;

import com.freejava.test_swagger.entity.ETF;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * ETF基金接口类
 */
@RestController
@RequestMapping("/v1/api")
@Api("swagger ETFController of api")
public class ETFController {

    /**
     * 获取所有优质ETF数据
     *
     * @return
     */
    @GetMapping("/etf")
    @ApiOperation(value = "获取所有优质的ETF基金数据", notes = "返回ETF基金数据")
    public List<ETF> list() {
        List<ETF> etfData = new ArrayList<>();
        etfData.add(new ETF("515713", "食品ETF","1.00"));
        etfData.add(new ETF("513050", "中概互联网ETF", "2.056"));
        return etfData;
    }

    /**
     * 根据交易代码获取对应的ETF数据
     * @param code 交易代码
     * @return
     */
    @GetMapping("/etf/{code}")
    @ApiOperation(value = "根据交易diamante获取TF基金数据", notes = "返回查询的基金数据")
    public ETF getByCode(@PathVariable String code) {
        if (code == "515713") {
            return new ETF("515713", "食品ETF","1.00");
        } else if (code == "513050") {
            return new ETF("513050", "中概互联网ETF", "2.056");
        } else {
            return null;
        }
    }
}
